﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class DongiathuocDAL : BaseDAL, UTL.IBaseDAL 
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT *,b.TENTHUOC FROM dongiathuoc a join thuoc b on a.mathuoc=b.mathuoc";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM dongiathuoc WHERE mathuoc = '{0}'";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (dongiathuoc)obj;
            string sql = @"INSERT INTO dongiathuoc(mathuoc,ngay,dongia) VALUES('{0}','{1}','{2}'";
            sql = string.Format(sql,o.mathuoc,o.ngay,o.dongia);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (dongiathuoc)obj;
            string sql = @"UPDATE dongiathuoc SET ngay='{0}',dongia='{1}' where mathuoc='{2}'";
            sql = string.Format(sql,o.ngay,o.dongia,o.mathuoc);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable Select_thuoc()
        {
            string sql = @" SELECT mathuoc as id, tenthuoc as ten FROM thuoc";
            return ExecuteQuery(sql);
        }
        public DataTable Select_max()
        {
            string sql = @"SELECT max(mathuoc) as id FROM dongiathuoc";
            return ExecuteQuery(sql);
        }



        public bool deleteobj(object obj)
        {
            throw new NotImplementedException();
        }
    }
}
